//
//  AppDelegate.m
//  DoctorRen
//
//  Created by Macx on 2018/11/18.
//

#import "AppDelegate.h"
#import <Aspects/Aspects.h>
#import <ShareSDK/ShareSDK.h>
#import "QNDeviceSDK.h"
#import "DRLoginDataModel.h"
#import <UMCommon/UMCommon.h>
#import <UMAnalytics/MobClick.h>

@interface AppDelegate ()

@end

@implementation AppDelegate


- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    // Override point for customization after application launch.
    
    [self regisetShareSDK];
//    [self registerQNSDK];
    [self configUMeng];
    [UIViewController aspect_hookSelector:@selector(viewDidLoad)
                              withOptions:AspectPositionAfter
                               usingBlock:^(id<AspectInfo> info) {
                                   
                                   UIViewController *instance = info.instance;
                                   [instance.navigationController.navigationBar setBackgroundImage:[UIImage new] forBarMetrics:UIBarMetricsDefault];
                                   [instance.navigationController.navigationBar setTranslucent:NO];
                                   instance.navigationController.navigationBar.shadowImage = [UIImage new];
                                   instance.navigationItem.backBarButtonItem = [[UIBarButtonItem alloc] initWithImage:[[UIImage imageNamed:@"操作栏_返回_黑色"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] style:UIBarButtonItemStylePlain target:nil action:nil];
                                   //隐藏默认的返回箭头
                                   instance.navigationController.navigationBar.backIndicatorImage = [UIImage new];
                                   instance.navigationController.navigationBar.backIndicatorTransitionMaskImage = [UIImage new];
                               } error:NULL];
    
    UIStoryboard *mainSB = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
//    UIStoryboard *loginSB = [UIStoryboard storyboardWithName:@"Login" bundle:nil];
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    self.window.backgroundColor = [UIColor whiteColor];
    
//    DRUserModel *model = [DRLoginDataModel getUserModel];
//    if (model.token && model.token.length > 0 && [DRLoginDataModel isLogin]) {
        self.window.rootViewController = mainSB.instantiateInitialViewController;
//    }else{
//        self.window.rootViewController = loginSB.instantiateInitialViewController;
//    }
    [self.window makeKeyAndVisible];
    
    [SVProgressHUD setMinimumDismissTimeInterval:2.5];
    
    [[UIBarButtonItem appearance] setBackButtonTitlePositionAdjustment:UIOffsetMake(0, -60)
                                                         forBarMetrics:UIBarMetricsDefault];
    
    
    
    
    return YES;
}

-(void) regisetShareSDK{
    [ShareSDK registPlatforms:^(SSDKRegister *platformsRegister) {
        //QQ 069AFF34
        [platformsRegister setupQQWithAppId:@"1106821172" appkey:@"kHdJSFzgstbgQGpy"];
        
        //微信
        [platformsRegister setupWeChatWithAppId:@"wx03f8bdce13eee615" appSecret:@"be77213cda3e8c3fedae71dbee26cbcc"];
    }];
}

-(void) registerQNSDK{
    QNConfig *config = [[QNBleApi sharedBleApi] getConfig];
    config.showPowerAlertKey = YES;
    
    QNBleApi.debug = YES;
    NSString *file = [[NSBundle mainBundle] pathForResource:@"123456789" ofType:@"qn"];
    [[QNBleApi sharedBleApi] initSdk:@"123456789" firstDataFile:file callback:^(NSError *error) {
        
    }];
}

-(void) configUMeng{
    [UMConfigure initWithAppkey:@"5c63bc05b465f5a648000695" channel:@"App Store"];
    
    [MobClick setScenarioType:E_UM_NORMAL];
    
    [MobClick setCrashReportEnabled:YES];
    
    [MobClick setAutoPageEnabled:YES];
}

- (void)applicationWillResignActive:(UIApplication *)application {
    // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
    // Use this method to pause ongoing tasks, disable timers, and invalidate graphics rendering callbacks. Games should use this method to pause the game.
}


- (void)applicationDidEnterBackground:(UIApplication *)application {
    // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
    // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}


- (void)applicationWillEnterForeground:(UIApplication *)application {
    // Called as part of the transition from the background to the active state; here you can undo many of the changes made on entering the background.
}


- (void)applicationDidBecomeActive:(UIApplication *)application {
    // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
}


- (void)applicationWillTerminate:(UIApplication *)application {
    // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}


@end
